package dp;

/**
 * @author : Rookie
 * @description : 最小体力爬到顶楼
 * @date : 2023/6/15
 */
public class ClimbStairsII {

    public static void main(String[] args) {
        int[] cost = new int[]{10,15,20};
        int climb = climb(cost);
        System.out.println(climb);
    }

    private static int climb(int []cost) {
        int[] dp = new int[cost.length + 1];
        int n = cost.length;
        // 可以从0级或1级爬
        dp[0] = 0;
        dp[1] = 0;
        // 状态方程 从前两级中找最小值
        for (int i = 2; i <= n ; i++) {
            dp[i] = Math.min(dp[i-1] + cost[i-1],dp[i-2] + cost[i-2]);
            System.out.println("dp[" + i + "] = " + dp[i]);
        }
        return dp[n];
    }
}
